process.env.NODE_ENV = "production";

const { merge } = require("webpack-merge");
const commonConfig = require("./webpack.common");
const { DefinePlugin } = require("webpack");

const BundleAnalyzerPlugin =
  require("webpack-bundle-analyzer").BundleAnalyzerPlugin;

const plugins = [
  new DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }),
];

const shouldAnalyze = process.argv.includes("analyze");
if (shouldAnalyze) {
  plugins.push(new BundleAnalyzerPlugin({ analyzerPort: 9000 }));
}

module.exports = merge(commonConfig, {
  mode: "production",
  devtool: "source-map",
  plugins,
});
